<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/common_tag.jsp"%>
<script type="text/javascript">
	$(function() {
		initEasyUIStyle();
		ClassRoomService.getClassRoomKeyMap(function(data) {
			addOption(data);
		})
		
		$('#gradeGrid').datagrid( {
			nowrap : false,
			striped : true,
			collapsible : true,
			url : 'grade_loadGrade.do',
			sortName : 'code',
			sortOrder : 'desc',
			remoteSort : false,
			idField : 'id',
			fitColumns : true,
			fit : true,
			frozenColumns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				title : '编号',
				field : 'id',
				width : 80,
				sortable : true
			} ] ],
			columns : [ [ {
				field : 'name',
				title : '名称',
				width : 120
			}, {
				field : 'type',
				title : '类型',
				width : 120
			}, {
				field : 'classRoom.name',
				title : '教室',
				width : 120,
				formatter: function (value, rec) {
			         return rec.classRoom['name'];
			     }
			} ] ],
			pagination : true,
			rownumbers : true,
			toolbar : [ {
				id : 'btnadd',
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					$('#grade_dd').dialog('open');
			}
			}, {
				id : 'btnremove',
				text : '批量删除',
				iconCls : 'icon-remove',
				handler : function() {
					removeMore();
				}
			} ]
		});

		$('#grade_dd').dialog( {
			shadow : false,
			title : '添加班级',
			width :400,
			height : 200,
			buttons : [ {
				text : '提交',
				iconCls : 'icon-ok',
				handler : function() {
					if ($('#gradeForm').form('validate')) {
						$.ajax( {
							url : "grade_addGrade.do",
							type : "post",
							data : $("#gradeForm").serialize(),
							datatype : "json",
							success : function(data) {
								if (data.MSG == "success") {
									document.getElementById("gradeForm").reset();
									$("#gradeGrid").datagrid("reload");
									$('#grade_dd').dialog('close');
									parent.dialogCloseInfo('info', "数据已保存！");
								} else {
									parent.dialogCloseInfo('error', "数据保存错误！")
								}
							}
						});
					}
				}
			}, {
				text : '取消',
				handler : function() {
					$('#gradeForm').form('clear');
					$('#grade_dd').dialog('close');
				}
			} ]
		});
	});

	function addOption(data) {
		var optionName = $('#stuname');
		for ( var property in data) {
			var option ="<option value='"+property+"'>"+data[property]+"</option>";
			optionName.append(option);
		}
	}
</script>
<body style="padding: 0; margin: 0; width: 100%; height: 100%">
	<table id="gradeGrid"></table>
	
	<div id="grade_dd" icon="icon-save" closed="true">
	<form id="gradeForm" method="post">
		<s:token />
		<div class="pageForm">
			<div class="pageFormContent">
				<dl>
					<dt>
						班级名称：
					</dt>
					<dd>
						<input name="grade.name" type="text" class="required" />
					</dd>
				</dl>
				<dl>
					<dt>
						类型：
					</dt>
					<dd>
						<select class="combox required" name="grade.type" id="type">
							<option value="1" selected="selected">
								普通班级
							</option>
							<option value="2">
								兴趣班
							</option>
						</select>
					</dd>
				</dl>
				<dl>
					<dt>
						教室：
					</dt>
					<dd>
						<select class="combox required" name="grade.classRoom.id"
							id="stuname">
						</select>
					</dd>
				</dl>
			</div>
		</div>
	</form>

</div>
</body>
